var express = require('express');
const { memberRooms, memberFriends, memberFriendApplies, memberSearch } = require('../controllers/member');
var router = express.Router();

/* member friends list. */
router.post('/friends', function(req, res, next) {
    memberFriends(req.member.id)
        .then((friends) => res.json({friends}));
});

/* member room list. */
router.post('/rooms', async function(req, res, next) {
    memberRooms(req.member.id)
        .then((rooms) => res.json({rooms}));
});

/* member friend apply list. */
router.post('/applies', async function(req, res, next) {
    memberFriendApplies(req.member.id)
        .then((applies) => res.json({applies}));
});

/* search member list. */
router.post('/search', async function(req, res, next) {
    // if(!req.body?.keyword) {
    //     res.json({members: []});
    //     return;
    // }
    memberSearch(req.body.keyword, req.member.id)
        .then((members) => res.json({members}));
});

module.exports = router;
